package Hot100.twoSearch;

public class searchInsert {
    public static void main(String[] args) {
        int nums[] = {1,3};
        System.out.println(new searchInsert().searchInsert(nums,2));
    }
    public int searchInsert(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int mid = 0;
        if(target < nums[0])
            return 0;
        else if(target > nums[nums.length - 1])
            return nums.length;
        while (left <= right){
             mid= (left + right) / 2;
            if(target > nums[mid]){
                left = mid + 1;
            } else if (target == nums[mid]) {
                return mid;
            }else {
                right = mid - 1;
            }
        }
        return mid+1;
    }
}
